Imports System.Text
Imports IICBusinessLogic.PeriodProcessing
Imports IICBusinessLogic

<TestClass()>
Public Class TestDiplomaProcessorReverser

    <TestMethod()>
    Public Sub TestReversePassFromClassAndExceptionMultiplePeriods()

        ModelContext.newForUnitTests()

        Try
            ModelContext.beginTrans()

            PeriodProcessorTestUtils.initialize()

            Dim mpt As New MultiplePeriodTest
            mpt.setupMultiplePeriodTest()

            Dim periodprocess As PeriodProcess = mpt.SecondPeriodProcessor.PeriodProcess
            Dim periodprocessId As Integer = periodprocess.PeriodProcessId
            Dim period As Period = mpt.SecondPeriodProcessor.period
            Dim preverse As PeriodProcessReverser = New PeriodProcessReverser(period)
            preverse.reversePeriodProcess()

            periodprocess = Nothing
            periodprocess = PeriodProcessDataUtils.findByKey(periodprocessId)
            Assert.IsNotNull(periodprocess.ReversalDate)

            Assert.IsNull(ClassMemberDataUtils.findOne("PeriodProcessId={0}", _
                                                       periodprocess.PeriodProcessId))

            Assert.IsNull(CertificationEarnedDataUtils.findOne("EarnedPeriodProcessId={0}", _
                                    periodprocess.PeriodProcessId))

            Assert.IsNull(DiplomaEarnedDataUtils.findOne("EarnedPeriodProcessId={0}", _
                                    periodprocess.PeriodProcessId))

            'make sure that the diploma earned on the first period is still there!
            Assert.AreEqual(1, DiplomaEarnedDataUtils.findList("EarnedPeriodProcessId={0}", _
                                    mpt.FirstPeriodProcessor.PeriodProcess.PeriodProcessId).Count)

            ModelContext.rollbackTrans()
        Finally
            ModelContext.rollbackTrans()
        End Try


    End Sub

End Class
